"use strict";
cc._RF.push(module, '890c4EMLCRGjp1c+CiCRB9i', 'UcAd');
// scripts/UcAd.js

"use strict";

var e = require;
var t = module;
var o = exports;

var _ii,
    nn = void 0 && (void 0).__extends || (_ii = function ii(t, e) {
  return (_ii = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _ii(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    rr = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
};

var oo = void 0 && (void 0).__decorate || function (e, t, a, n) {
  var i,
      o = arguments.length,
      s = o < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);else for (var r = e.length - 1; r >= 0; r--) {
    (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
  }
  return o > 3 && s && Object.defineProperty(t, a, s), s;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});
var a = e("AdInterface"),
    n = cc._decorator,
    i = n.ccclass,
    r = (n.property, function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    return t.game_version = "101", t.app_test_version = !1, t.UcSysInfo = null, t.videoAd = null, t.loadSucc_Video = null, t.callback_Video = null, t.loadSucc_Banner = !1, t.bannerAd = null, t.loadSucc_SystemBanner = !1, t.NUM_CheckBannerLoadSucc = 0, t.NUM_MaxCheckBannerLoadSucc = 5, t.hasShowBanner = !1, t.isShow_SystemBanner = !1, t.interval_updateBanner = null, t.timeout_showSystemBanner = null, t.timeout_checkBannerLoadSucc = null, t.systemIntersAd = null, t.loadSucc_SystemInters = !1, t.NUM_SystemIntersLoadError = 0, t.NUM_IntersNowIntervalTime = 0, t.NUN_hasVideoShowInters = 0, t;
  }

  return nn(t, e), t.prototype.GameVersion = function (e) {
    this.app_test_version = this.game_version == e;
  }, t.prototype.getGameTestVersion = function () {
    return this.app_test_version;
  }, t.prototype.createAd = function () {
    console.log("=====UC===创建广告=====");
    var e = this;
    uc.getSystemInfo({
      success: function success(t) {
        console.log("====uc==createInterstitialAd====res====", t), e.UcSysInfo = t, e.UcCreateAdInfo();
      },
      fail: function fail(e) {
        console.log("====uc==createInterstitialAd====err====", e), console.error(e);
      }
    });
  }, t.prototype.UcCreateAdInfo = function () {
    this.SW_Video && "" != this.ID_Video && this.createVideo(), this.SW_System_Banner && "" != this.ID_System_Banner && this.createSystemBanner(), this.SW_System_Inters && "" != this.ID_System_Inters && this.createSystemInters(), this.NUM_IntersIntervalTime > 0 && this.runIntersInterval();
  }, t.prototype.createVideo = function () {
    var e = this;
    this.videoAd = uc.createRewardVideoAd(), this.videoAd.onLoad(function () {
      console.log("UC 视频广告加载完成"), e.loadSucc_Video = !0;
    }), this.videoAd.onError(function (t) {
      console.log("UC 视频加载失败：", JSON.stringify(t)), e.loadSucc_Video = !1, setTimeout(function () {
        e.videoAd && e.videoAd.load();
      }, 3e3);
    }), this.videoAd.onClose(function (t) {
      t && t.isEnded ? (console.log("UC 激励视频广告完成，发放奖励"), e.callback_Video && (e.callback_Video(!0), e.callback_Video = null)) : (console.log("UC 激励视频广告取消关闭，不发放奖励"), e.callback_Video && (e.callback_Video(!1), e.callback_Video = null)), e.loadSucc_Video = !1, setTimeout(function () {
        e.videoAd && e.videoAd.load();
      }, 3e3);
    });
  }, t.prototype.getVideoFlag = function () {
    return this.loadSucc_Video;
  }, t.prototype.showVideo = function (e) {
    this.videoAd && this.loadSucc_Video && (this.callback_Video = e, this.videoAd.show());
  }, t.prototype.createSystemBanner = function () {
    var e = this,
        t = (this.UcSysInfo.screenWidth > this.UcSysInfo.screenHeight ? this.UcSysInfo.screenHeight : this.UcSysInfo.screenWidth) / 2,
        o = {
      width: t,
      height: 194 * t / 345,
      gravity: 7
    };
    this.bannerAd = uc.createBannerAd({
      style: o
    }), this.bannerAd.onLoad(function () {
      e.loadSucc_SystemBanner = !0, console.log("UC 系统banner加载成功");
    }), this.bannerAd.onError(function (t) {
      console.log("UC 系统banner加载失败：", JSON.stringify(t)), e.bannerAd = null, e.loadSucc_SystemBanner = !1;
    });
  }, t.prototype.checkBannerLoadSucc = function () {
    var e = this;
    if (this.loadSucc_Banner = this.loadSucc_SystemBanner, console.log("banner加载成功?", this.loadSucc_Banner, ++this.NUM_CheckBannerLoadSucc), this.timeout_checkBannerLoadSucc && clearTimeout(this.timeout_checkBannerLoadSucc), this.loadSucc_Banner) this.showBanner();else {
      if (this.NUM_CheckBannerLoadSucc >= this.NUM_MaxCheckBannerLoadSucc) return;
      this.timeout_checkBannerLoadSucc = setTimeout(function () {
        e.checkBannerLoadSucc();
      }, 5e3);
    }
  }, t.prototype.showBanner = function () {
    this.loadSucc_Banner ? this.hasShowBanner ? console.log("已经调用过showBanner,请勿重复调用") : (this.hasShowBanner = !0, this.showSystemBanner(), this.updateBanner()) : this.checkBannerLoadSucc();
  }, t.prototype.showSystemBanner = function () {
    var e = this;
    this.bannerAd && this.UcSysInfo ? (console.log("UC showSystemBanner========================"), this.isShow_SystemBanner = !0, this.bannerAd.show()) : (this.createSystemBanner(), this.timeout_showSystemBanner = setTimeout(function () {
      e.bannerAd && e.showSystemBanner();
    }, 1e3));
  }, t.prototype.updateBanner = function () {
    var e = this;
    this.interval_updateBanner && clearInterval(this.interval_updateBanner), this.interval_updateBanner = setInterval(function () {
      e.updateSystemBanner();
    }, 1e3 * this.Control_Banner_Update);
  }, t.prototype.updateSystemBanner = function () {
    var e = this;
    console.log("UC updateSystemBanner========================"), this.hideSystemBanner(), this.createSystemBanner(), this.timeout_showSystemBanner = setTimeout(function () {
      e.bannerAd && e.showSystemBanner();
    }, 1e3);
  }, t.prototype.hideSystemBanner = function () {
    this.isShow_SystemBanner && this.bannerAd && (console.log("UC hideSystemBanner========================"), this.isShow_SystemBanner = !1, this.bannerAd.destroy());
  }, t.prototype.hideBanner = function () {
    this.hasShowBanner = !1, this.hideSystemBanner(), this.interval_updateBanner && clearInterval(this.interval_updateBanner), this.timeout_showSystemBanner && clearTimeout(this.timeout_showSystemBanner), this.timeout_checkBannerLoadSucc && clearTimeout(this.timeout_checkBannerLoadSucc);
  }, t.prototype.createSystemInters = function () {
    var e = this;
    this.loadSucc_SystemInters || (console.log("--createSystemInters--"), this.systemIntersAd = uc.createInterstitialAd(), this.systemIntersAd.load().then()["catch"](function (e) {
      return console.log(e);
    }), this.systemIntersAd.onLoad(function () {
      console.log("UC 系统插屏广告加载完成"), e.loadSucc_SystemInters = !0;
    }), this.systemIntersAd.onError(function (t) {
      e.NUM_SystemIntersLoadError++, e.loadSucc_SystemInters = !1, console.log(e.NUM_SystemIntersLoadError, "UC 系统插屏加载失败：", JSON.stringify(t)), e.NUM_SystemIntersLoadError < 5 && setTimeout(function () {
        e.createSystemInters();
      }, 1e4);
    }), this.systemIntersAd.onClose(function () {
      console.log("UC 系统插屏广告关闭"), e.NUM_IntersNowIntervalTime = 0, e.loadSucc_SystemInters = !1, setTimeout(function () {
        e.createSystemInters();
      }, 1e4);
    }));
  }, t.prototype.getIntersFlag = function () {
    return this.loadSucc_SystemInters;
  }, t.prototype.showInters = function () {
    var e = this;

    if (this.getIntersFlag()) {
      if (console.log("UC 展示插屏广告"), !this.getGameTestVersion() && this.Control_Video && this.Control_Inters_To_Video_Switch && this.NUN_hasVideoShowInters > 0) {
        if (console.log("UC 第" + this.Control_Start_Inters_To_Video + "次插屏变视频", "当前第" + this.NUN_hasVideoShowInters + "次"), this.NUN_hasVideoShowInters == this.Control_Start_Inters_To_Video) return console.log("UC 首次插屏变视频"), this.NUN_hasVideoShowInters++, void this.showVideo(function () {});
        if (this.Control_Inters_To_Video > 0 && this.NUN_hasVideoShowInters % this.Control_Inters_To_Video == 0) return console.log("UC 间隔插屏变视频"), this.NUN_hasVideoShowInters++, void this.showVideo(function () {});
      }

      this.Control_Delay_Time > 0 && Math.floor(100 * Math.random()) < this.Control_Delay_Prob ? (console.log("插屏延迟时间(ms):" + this.Control_Delay_Time), setTimeout(function () {
        e.showSystemInters();
      }, this.Control_Delay_Time)) : this.showSystemInters(), this.NUN_hasVideoShowInters++;
    } else console.log("UC  插屏广告暂未开启************请在后台确认是否开启***************");
  }, t.prototype.showSystemInters = function () {
    if (this.systemIntersAd) {
      if (console.log("UC showSystemInters=================="), !this.UcSysInfo || this.UcSysInfo.SDKVersion < "1.1.2") return;
      this.systemIntersAd && this.systemIntersAd.show().then(function () {
        console.log("UC 系统插屏广告展示成功==================");
      })["catch"](function (e) {
        console.log("UC 系统插屏展示错误:" + JSON.stringify(e));
      });
    }
  }, t.prototype.runIntersInterval = function () {
    var e = this;
    this.NUM_IntersIntervalTime > 0 && setInterval(function () {
      e.NUM_IntersNowIntervalTime++;
    }, 1e3);
  }, t.prototype.setGroup = function (e) {
    this.AdGroup = e;
  }, t.prototype.hasAddDesktopFunc = function () {
    return !1;
  }, t.prototype.getErrorControl = function () {
    var e = !1;
    return this.getGameTestVersion() || (e = this.adErrorControl()), e;
  }, t.prototype.getCustomErrorControl = function () {
    return !!this.getErrorControl() && this.getCustomError();
  }, oo([i], t);
}(a["default"]));
o["default"] = r;

cc._RF.pop();